#!/bin/bash

# 设置 NVIDIA 驱动、CUDA 和 cuDNN 的版本
#CUDA_VERSION="cuda_12.0.0_525.60.13_linux.run"
#CUDNN_VERSION="8.2.2"

# 下载 CUDA 安装包并安装
sudo rm -rf cuda_12.0.0_525.60.13_linux.run
wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run
sudo chmod +x cuda_12.0.0_525.60.13_linux.run
sudo ./cuda_12.0.0_525.60.13_linux.run --silent --toolkit --override

# 设置环境变量
echo 'export PATH=/usr/local/cuda-12.0/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc

# 下载 cuDNN 安装包并安装
#wget https://developer.download.nvidia.com/compute/redist/cudnn/v${CUDNN_VERSION}/cudnn-${CUDNN_VERSION}-linux-x64-v${CUDA_VERSION}.tgz
#sudo tar -xzvf cudnn-${CUDNN_VERSION}-linux-x64-v${CUDA_VERSION}.tgz -C /usr/local/
#sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

# 验证安装
nvcc --version
cat /usr/local/cuda/version.txt